#!/usr/bin/env python
#coding=utf-8
import json
import request
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.acs_exception.exceptions import ClientException
from aliyunsdkcore.acs_exception.exceptions import ServerException
from aliyunsdkcore.auth.credentials import AccessKeyCredential
from aliyunsdkcore.auth.credentials import StsTokenCredential
from aliyunsdkalidns.request.v20150109.UpdateDomainRecordRequest import UpdateDomainRecordRequest

def updateDnsRecord():
  credentials = AccessKeyCredential('LTAI5tPKYbJMddxzQe85TDwn', 'GpcYCCczOAWfCYFeRwyp61R8f3jdeY')
  client = AcsClient(region_id='cn-zhangjiakou', credential=credentials)

  request = UpdateDomainRecordRequest()
  request.set_accept_format('json')

  request.set_RecordId("726493909216982016")
  request.set_RR("xiaopijiang.top")
  request.set_Type("A")
  request.set_Value("192.168.0.1")

  response = client.do_action_with_exception(request)
  # python2:  print(response) 
  print(str(response, encoding='utf-8'))

def getOutIp():
  url = 'https://www.sogou.com/websearch/features/getTime.jsp'
  return json.loads(request.get(url))['ip']


ip = getOutIp()
print("ip:" + ip)
# updateDnsRecord()